﻿using System;
using System.Collections.Generic;
using System.IO;

using Microsoft.Xna.Framework;

namespace AlfarEngine.Components
{
    /// <summary>
    /// Abstract class that define a "Component", a specification of an object
    /// </summary>
    public abstract class AComponent
    {
        #region Members
        
        protected GameObject mOwner;

        #endregion

        //----------------------------------------

        #region Accessors

        /// <summary>
        /// The object on which this component is attached
        /// </summary>
        public GameObject owner { get { return mOwner; } }

        #endregion

        //-------------------------------------------

        #region Methods

        public AComponent(GameObject pOwner)
        {
            mOwner = pOwner;
        }

        /// <summary>
        /// Update this components (override to add specific behaviour)
        /// </summary>
        /// <param name="pTime"></param>
        public virtual void Update(GameTime pTime)
        {
        }

        /// <summary>
        /// Called when the engine Draw the component. Override to specify. This give a base color of white (no teint)
        /// </summary>
        /// <param name="pTime"></param>
        public virtual void Draw(GameTime pTime)
        {
            Draw(pTime, Color.White);
        }

        /// <summary>
        /// Called when the engine Draw the component. Override to specify.
        /// </summary>
        /// <param name="pTime"></param>
        public virtual void Draw(GameTime pTime, Color pColor)
        {
        }

        /// <summary>
        /// Serialize the component to XML.
        /// </summary>
        /// <param name="pFile"></param>
        /// <param name="pLevel"></param>
        public virtual void Serialize(BinaryWriter pFile)
        {
            pFile.Write(this.GetType().ToString());
        }

        public virtual void Deserialize(BinaryReader pFile)
        {

        }

        #endregion

    }
}
